package tools;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.ListIterator;

public class Message {
	
	private static List<String> logList = new ArrayList<String>();
	
	public static void putInLogger(String message){	
		String formattedMsg = "******\n" + message + "\n******";
		logList.add(formattedMsg);
	}
	
	@SuppressWarnings("deprecation")
	public static void displayAndSaveLogger(){		
		try {
			BufferedWriter output = null;
			Date date = new Date();
			FileWriter fw = new FileWriter("log" + date.getHours()+"h"+date.getMinutes()+"m"+date.getSeconds()+"s" , true);
			output = new BufferedWriter(fw);
			ListIterator<String> iterat = logList.listIterator(logList.size());
			
			while(iterat.hasPrevious()){
				String prev = iterat.previous();
				System.out.println(prev);
				output.write(prev);					
				output.flush();
			}			
			
			output.close();
			for (int i = 0; i < logList.size(); i ++){
				logList.remove(i);
			}
			
			} catch (IOException e) {
				e.printStackTrace();
			}		
	}
	
}
